package org.papervision3d.core.proto
{
	import org.papervision3d.cameras.Camera3D;
	import flash.events.Event;
	import org.papervision3d.events.MouseEventManager;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	
	public class MappingEventCallback extends MouseEventCallback
	{
		
		
		function MappingEventCallback( scene : SceneObject3D, camera : CameraObject3D ) {
			super( scene, camera );
			
			
		}
		
		override protected function _checkForMatch( e : Event ) : void {
			x = scene.container.mouseX;
			y = scene.container.mouseY;
			
			curpath = new Array();
			object = null;
	        tri = null;
	        face3d = null;
	        path = null;
	        
			scene.naRendering( camera, this );

	        match = ( object != null );

			if( match ){
				coordAtPoint = face3d.getCoordAtPoint( x, y );
				normalAtPoint = face3d.getNormal();
				materialCoordinates = tri.getMapCoordAtPoint( x, y );
				MouseEventManager.instance.dispatch( MouseEvent.MOUSE_MOVE, path, this );
			}
			
			if( previousMatch != object ) {
				
				if( path && previousPath){
					var paths : Object = getCleanPaths( previousPath, path );
					
					
					if( paths.prevPath.length > 0) MouseEventManager.instance.dispatch( MouseEvent.MOUSE_OUT, paths.prevPath, this );
					if( paths.path.length > 0)MouseEventManager.instance.dispatch( MouseEvent.MOUSE_OVER, paths.path, this );
				} else if( previousPath){
					MouseEventManager.instance.dispatch( MouseEvent.MOUSE_OUT, previousPath, this )
				} else {
					MouseEventManager.instance.dispatch( MouseEvent.MOUSE_OVER, path, this );
				}
			}
			
			previousPath = path;
			previousMatch = object;
			
		}
	}
}